const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = function (app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://127.0.0.1:8080', // 后台服务地址以及端口号
      changeOrigin: true, // 是否开启代理
      logLevel: 'debug', // 添加调试日志
      onProxyReq: (proxyReq, req, res) => {
        console.log('代理请求:', req.method, req.url, '->', proxyReq.getHeader('host') + proxyReq.path);
      },
      onProxyRes: (proxyRes, req, res) => {
        console.log('代理响应:', proxyRes.statusCode, req.url);
      },
      onError: (err, req, res) => {
        console.log('代理错误:', err.message, req.url);
      }
    })
  )
}


